package com.huawei.secure.android.common.anonymization;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class a {
    public static String[] a(@NonNull String[] strArr, @NonNull String[] strArr2) {
        if (strArr.length <= 0) {
            if (strArr2.length <= 0) {
                return new String[0];
            }
            return strArr2;
        } else if (strArr2.length <= 0) {
            return strArr;
        } else {
            Object obj = new String[(strArr.length + strArr2.length)];
            System.arraycopy(strArr, 0, obj, 0, strArr.length);
            System.arraycopy(strArr2, 0, obj, strArr.length, strArr2.length);
            return obj;
        }
    }

    public static String[] a(String str, String[] strArr) {
        return a(new String[]{str}, strArr);
    }

    public static String[] a(String[] strArr, String str) {
        return a(strArr, new String[]{str});
    }

    public static String[] a(String str, int i, int i2) {
        String[] split = split(str, i);
        return a(a(split, 0), split(a(split, 1), i2 - i));
    }

    public static String[] a(String str, int i, int i2, int i3) {
        String[] split = split(str, i);
        return a(a(split, 0), a(a(split, 1), i2 - i, i3 - i));
    }

    public static String[] a(@Nullable String str, int... iArr) {
        if (str == null) {
            return new String[]{""};
        } else if (str.length() <= 1 || iArr.length <= 0) {
            return new String[]{str};
        } else if (iArr.length <= 1) {
            return split(str, iArr[0]);
        } else {
            int i = iArr[0];
            int[] iArr2 = new int[(iArr.length - 1)];
            for (int i2 = 0; i2 < iArr2.length; i2++) {
                iArr2[i2] = iArr[i2 + 1] - i;
            }
            String[] split = split(str, i);
            return a(a(split, 0), a(a(split, 1), iArr2));
        }
    }

    public static String[] split(@Nullable String str, int i) {
        if (str == null) {
            return new String[]{"", ""};
        } else if (i < 0 || i > str.length()) {
            return new String[]{str, ""};
        } else {
            return new String[]{str.substring(0, i), str.substring(i)};
        }
    }

    public static String[] a(@Nullable String str, char c) {
        if (str == null) {
            return new String[0];
        }
        if (str.length() <= 0) {
            return new String[]{str};
        }
        int i;
        int i2 = 1;
        for (i = 0; i < str.length(); i++) {
            if (str.charAt(i) == c) {
                i2++;
            }
        }
        if (i2 <= 1) {
            return new String[]{str};
        }
        String[] strArr = new String[i2];
        StringBuilder stringBuilder = new StringBuilder(str.length());
        int i3 = 0;
        for (i = 0; i < str.length() && i3 < i2; i++) {
            char charAt = str.charAt(i);
            if (charAt == c) {
                int i4 = i3 + 1;
                strArr[i3] = stringBuilder.toString();
                stringBuilder.setLength(0);
                i3 = i4;
            } else {
                stringBuilder.append(charAt);
            }
        }
        strArr[i3] = stringBuilder.toString();
        return strArr;
    }

    public static String b(@NonNull String str, String... strArr) {
        if (strArr == null || strArr.length <= 0) {
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder(strArr[0]);
        for (int i = 1; i < strArr.length; i++) {
            if (strArr[i] != null) {
                stringBuilder.append(str).append(strArr[i]);
            }
        }
        return stringBuilder.toString();
    }

    public static String a(@Nullable String str, @NonNull String str2, @NonNull String str3) {
        if (str == null || str.length() <= 0 || str2.length() <= 0 || str3.length() <= 0) {
            return str;
        }
        char[] toCharArray = str.toCharArray();
        char[] cArr = new char[str.length()];
        char charAt = str3.charAt(str3.length() - 1);
        for (int i = 0; i < toCharArray.length; i++) {
            char c = toCharArray[i];
            int lastIndexOf = str2.lastIndexOf(c);
            if (lastIndexOf < 0) {
                cArr[i] = c;
            } else {
                cArr[i] = lastIndexOf >= str3.length() ? charAt : str3.charAt(lastIndexOf);
            }
        }
        return new String(cArr);
    }

    public static String a(String[] strArr, int i) {
        if (strArr == null || strArr.length <= 0) {
            return "";
        }
        if (i < 0 || i >= strArr.length) {
            return "";
        }
        return strArr[i];
    }

    public static String b(String str, char c) {
        if (str == null || str.length() <= 0) {
            return "";
        }
        char[] cArr = new char[str.length()];
        for (int i = 0; i < cArr.length; i++) {
            cArr[i] = c;
        }
        return new String(cArr);
    }

    public static int a(@NonNull String str, char c, int i) {
        int length = str.length() - 1;
        int i2 = i;
        while (length >= 0) {
            if (str.charAt(length) == c) {
                i2--;
                if (i2 <= 0) {
                    break;
                }
            }
            length--;
        }
        return length;
    }
}
